Documentation for Users  2.1.2
Perception Toolbox for Virtual Reality (PTVR) Manual
mnread_cardboard.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 Created on Fri Jun 25 09:37:44 2021
4 
5 @author: Johanna Delachambre
6 
7 This demo recreate the MNRead Carboard, by displaying 3 sentences at 3 different sizes.
8 
9 """
10 
11 import os
12 import subprocess
13 
14 # from sys import exit
15 import PTVR.SystemUtils
16 
17 import sys
18 from math import *
19 import math
20 import random
21 
22 import numpy as np
23 import PTVR.Visual as visual
27 import PTVR.Data.Input as input
28 import PTVR.Stimuli.Color as color
29 import PTVR.mnread_phrase_cutting as mnread
30 import PTVR.VisualAngleCalculation as VAcalcul
31 import Parameters.cardboard_mnread_parameters as parameters
32 
33 
34 username = "DemoName"
35 
36 heightOfStaticPOV_m = 0
37 
38 
40  """Displays 3 phrases like in the board version of MNRead """
41  # Creation of the scene
42  POVatCalibration = PTVR.Stimuli.Objects.VirtualPoint(
43  position_current_CS=np.array([0, heightOfStaticPOV_m, 0]))
44  my_world.set_coordinate_system_from_a_virtual_point(POVatCalibration)
45  t1 = PTVR.Stimuli.Scenes.VisualScene(experiment=exp)
46 
47  # The tangent screen is the screen behind the text
48  tangent_screen = PTVR.Stimuli.Objects.FlatScreen(position_current_CS=(0, 0, (parameters.viewing_distance_in_m+0.1)),
49  color=parameters.tangent_screen_color, size_in_meters=np.array([parameters.tangent_screen_width, parameters.tangent_screen_height]))
50  tangent_screen.SetTangentRotation()
51  tangent_screen.set_perimetric_coordinates(eccentricity=0.0, halfMeridian=0.0,
52  radialDistance=parameters.viewing_distance_in_m)
53  t1.place(tangent_screen)
54 
55  # Variable with the current visual angle. Used to decrease the size of each sentence
56  current_visual_angle_of_centered_object = parameters.visual_angle_of_centered_object
57  # Position of the text in the y-axis
58  y_text_position_current_CS = (VAcalcul.visual_angle_to_size_on_tangent_screen(
59  current_visual_angle_of_centered_object, parameters.viewing_distance_in_m) * 10)
60 
61  for i in range(len(parameters.phrases_to_display)):
62 
63  # Transformation of the phrase in order to have 3 lines following the MNRead's standards
64  list_cutted_phrases_from_mnread_phrase_cutting = mnread.mnread_phrase_cutting(
65  parameters.phrases_to_display[i])
66  phrase_with_back_to_line = list_cutted_phrases_from_mnread_phrase_cutting[0] + "\n" + \
67  list_cutted_phrases_from_mnread_phrase_cutting[1] + \
68  "\n" + list_cutted_phrases_from_mnread_phrase_cutting[2]
69 
70  text = PTVR.Stimuli.Objects.Text(text=phrase_with_back_to_line, horizontal_alignment=parameters.text_alignment, font_name=parameters.font_to_use, color=parameters.text_color, position_current_CS=(
71  0, y_text_position, parameters.viewing_distance_in_m), visual_angle_of_centered_x_height_deg=current_visual_angle_of_centered_object)
72  text.SetMnreadFormat()
73 
74  tangent_screen.place_object_on_tangent_screen(text)
75 
76  # Management of the current visual angle in order to decrease the size of the next phrase and management of the position in y-axis
77  visual_angle_of_centered_object_in_logmar = VAcalcul.visual_angle_in_degrees_to_logmar(
78  current_visual_angle_of_centered_object)
79  current_visual_angle_of_centered_object = VAcalcul.logmar_to_visual_angle_in_degrees(
80  visual_angle_of_centered_object_in_logmar - parameters.decreasing_size)
81  y_text_position -= VAcalcul.visual_angle_to_size_on_tangent_screen(
82  current_visual_angle_of_centered_object, parameters.viewing_distance_in_m)*10
83 
84  t1.place(text)
85  my_world.add_scene(t1)
86 
87 
88 def main():
89 
90  # Set-up the experiment file
91  my_world = visual.The3DWorld()
92 
93  cardboard_mnread(exp)
94 
95  # Write The3DWorld to file
96  my_world.write()
97  print("The experiment has been written.")
98 
99 
100 if __name__ == "__main__":
101  main()
102 
def LaunchThe3DWorld(jsonFileCategory="Externals")
Definition: SystemUtils.py:182
def cardboard_mnread(exp)